// JavaScript Document

var winw=$(window).width(),
	winh=$(window).height();

var navh,	// 存储当前左侧导航栏的高度
	n_wh;	// 存储当前导航栏与屏幕可见区域的差值


var userimg='img/navimg/userimg.jpg',	// 用户头像图片
	username='wuli凡wuli凡wuli凡';	//用户名称
var path="";
$(function(){
	 //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath=window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht=curWwwPath.substring(0,pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    if(projectName=='/star-controller'){//要避免controller使用此链接
        path=localhostPaht+projectName;
    }else{
    	path = localhostPaht;
    }
    $.ajax({
		url:path+'/getLoginInfo',
		type:'post',
		data:{},
		async:false,
		dataType:'json',
		success:function(data){
			data=eval('('+data+')');
			userimg=data.img;
			username=data.nickname;
		}
	});
   /* html ='<div class="nav "><div class="logobox"><img src="'+path+'/jsp/img/navimg/logo.png"class="logoimg"></div><div class="userbox"><div class="userimg"><img class="headImg_pub" src="'+userimg+'"></div><div class="username"><p id="userName_pub1">'+username+'</p></div></div>';
    html+='<dl class="navbox">';
    html+='<a href="'+path+'/starLiveInfo/getIndxData"><dd><div class="navli"><span class="icon nav1"></span><span class="text">首&emsp;&emsp;页</span></div></dd></a>';
    html+='<a href="'+path+'/transfer/directseeddeta"><dd><div class="navli"> <span class="icon nav2"></span><span class="text">直播明细</span> </div> </dd></a>';
    html+='<a href="'+path+'/starLiveInfo/presentLog"><dd><div class="navli"><span class="icon nav3"></span><span class="text">礼物收入</span></div> </dd></a>';
    html+='<a href="'+path+'/transfer/exchangedetail"><dd> <div class="navli"> <span class="icon nav4"></span><span class="text">兑换明细</span> </div> </dd></a>';
    html+='<a href="'+path+'/presentLogAll/fansRank"><dd> <div class="navli"> <span class="icon nav5"></span><span class="text">粉丝排行榜</span> </div> </dd></a>';
    html+='<a href="'+path+'/presentLogAll/persentRank"><dd> <div class="navli"> <span class="icon nav6"></span><span class="text">礼物排行榜</span> </div> </dd></a>';
    html+='<a href="'+path+'/punish/punishData"><dd> <div class="navli"> <span class="icon nav7"></span><span class="text">违规列表</span> </div> </dd></a>';
    html+='<a href="'+path+'/memberRole/getMemberRole"><dd> <div class="navli"> <span class="icon nav8"></span><span class="text">管理员管理</span></div></dd></a>';
    html+='<a href="'+path+'/club/list"><dd> <div class="navli"> <span class="icon nav9"></span><span class="text">俱乐部管理</span> </div> </dd></a>';
    html+='<a href="'+path+'/personSet/personInfo"><dd> <div class="navli"> <span class="icon nav10"></span><span class="text">个人设置</span> </div> </dd></a>';
    html+='<span class="navmack"></span></dl></div>';*/
	$(".main").append(html);
	$(".cont").append('<div class="scubox"><div class="scudv"><div class="scuimg"><img class="headImg_pub" src="'+userimg+'"></div><p class="scuname" id="userName_pub">'+username+'</p><span class="scuarrow" onclick="exit()">退出</span></div></div>');
	
	});



window.onload=function(){
	$(".nav").css({'min-height':winh+'px'});	// 左侧导航栏高度 最小等于屏幕可见区域高度
	navh=$(".nav").height();	// 获取左侧导航栏高度
	$(".cont").css({'min-height':navh+'px'});	// 右侧内容栏最小高度等于左侧导航栏高度
	n_wh = navh-winh; // 导航栏高度与屏幕高度差值
	
	if(n_wh > 0){ //导航栏高度大于屏幕可见区域
		$(window).scroll(function(){
			var scrnum=$(window).scrollTop();
			console.log('scrnum='+scrnum);
			if(scrnum < n_wh){
				$(".nav").removeClass('navfixd');
				}
			else{
				$(".nav").addClass('navfixd')
				}
			});
		}
	else{	// 导航栏高度等于屏幕可见高度
		$(".nav").css({'position':'fixed','top':'0px'});
		}
	
	
	// 回到顶端按钮位置
	$(".zygotop").css({'left':(winw/2+510)+'px'});
	
	$(".zygotop").off().on("click",function(){
		$("html, body").animate({scrollTop:0},500);
		});
	
	
	}


$(function(){
	// nav 点击事件
	$(".navbox dd").off().on("click",function(){
		var num=$(".navbox dd").index(this);
			console.log('num='+num);
		$(".navbox dd").removeClass('navnow');
		$(this).addClass('navnow');
		$(".navmack").css({'top':(num*50)+'px'});
		});
	
	// 左侧导航栏 头像点击事件
	$(".userimg").off().on("click",function(){
		window.open(path+'/personSet/personInfo','_self');
		});
		
	// 顶部 头像 点击事件
	$(".scuimg").off().on("click",function(){
		window.open(path+'/personSet/personInfo','_self');
		});
	
	
	});


// 检测页面滚动条距离顶端的高度
$(window).scroll(function(){
	var num=$(window).scrollTop();
	if(num >= 300){
		$(".zygotop").fadeIn();
		}
	else{
		$(".zygotop").fadeOut();
		}
	});

function FormatDate (strTime,pattern) {
    var date = new Date(strTime);
    var _year=date.getFullYear();
    var _month=(date.getMonth()+1);
    var _day = date.getDate();
    var _hour=date.getHours();
    var _minutes = date.getMinutes();
    var _ss=date.getSeconds();
    var str;
    if(pattern =='yyyy-MM-dd HH:ss'){
	    if(_month<10){
	    	_month="0"+_month;
	    }
	    if(_day<10){
	    	_day="0"+_day;
	    }
	    if(_hour<10){
	    	_hour="0"+_hour;
	    }
	    if(_minutes<10){
	    	_minutes="0"+_minutes;
	    }
	    str=_year+"-"+_month+"-"+_day+" "+_hour+":"+_minutes;
    }else if(pattern =='yyyy-MM-dd'){
	    if(_month<10){
	    	_month="0"+_month;
	    }
	    if(_day<10){
	    	_day="0"+_day;
	    }
	    str=_year+"-"+_month+"-"+_day;
    }else if(pattern =='yyyy-MM-dd HH:mm:ss'){
	    if(_month<10){
	    	_month="0"+_month;
	    }
	    if(_day<10){
	    	_day="0"+_day;
	    }
	    if(_hour<10){
	    	_hour="0"+_hour;
	    }
	    if(_minutes<10){
	    	_minutes="0"+_minutes;
	    }
	    str=_year+"-"+_month+"-"+_day+" "+_hour+":"+_minutes+":"+_ss;
    }
    return str;
}

function toHourMinute(minutes){
	if(minutes>0){
		var _h=Math.floor(minutes/3600);
		var ym= minutes%3600;
		var _m = Math.floor(ym/60);
		if(_h>0&&_m!=0){
			return _h + "小时"+ _m+ "分钟";
		}else if(_h>0&&_m == 0){
			return _h+"小时";
		}else{
			return _m+ "分钟";
		}
	}else{
		return "0";
	}
	
}
function exit(){
	window.location.href=path+"/exit";
}



